create PROCEDURE [dbo].[sp_first_wait] (@fpRole varchar(10),@UnitId varchar(30))
AS
BEGIN
set nocount on--关闭计数

declare @tmpTab table (tRow int identity(1,1),wCount int,menuNo varchar(20),clewDesc varchar(400))
--  条件值初始化 {
  declare @deptId varchar(30)
  if len(@UnitId) <> 0
    select @deptId = @UnitId
  else
    select @deptId = '-1'
--  条件值初始化 }
--print len(@fpParent)
--print @staPid
-- 变量定义 vs @tmpTab {
declare @pwCount int,@pmenuNo varchar(20),@pclewDesc varchar(400)
-- 变量定义 vs @tmpTab }
declare @tmpInt int

--Adm
IF CHARINDEX(@fpRole, '-10,-11,110,120,180,185,190')>0
Begin
  select @pmenuNo='3102'
  select @tmpInt=count(PkId) from [tWorkFormBase] where CrtStepID in (100,103) and IsDel=0
  if @tmpInt is null
     select @pwCount=0
  else
     select @pwCount=@tmpInt
  if @pwCount<>0
     select @pclewDesc='未分派电话工单：<span class="spLRed">'+cast(@pwCount as varchar(5))+'</span> 件'
  else
     select @pclewDesc='未分派电话工单：0 件'
  INSERT into @tmpTab(wCount,menuNo,clewDesc) VALUES(@pwCount,@pmenuNo,@pclewDesc)

  select @pmenuNo='2311'
  select @tmpInt=count(PkId) from [mMailGetDeal] where StateFlag=141 and IsDel=0
  if @tmpInt is null
     select @pwCount=0
  else
     select @pwCount=@tmpInt
  if @pwCount<>0
     select @pclewDesc='未受理信件：<span class="spLRed">'+cast(@pwCount as varchar(5))+'</span> 件'
  else
     select @pclewDesc='未受理信件：0 件'
  INSERT into @tmpTab(wCount,menuNo,clewDesc) VALUES(@pwCount,@pmenuNo,@pclewDesc)

  select @pmenuNo='2601'
  select @tmpInt=count(PkId) from [pMsgGetDeal] where StateFlag in (171,181) and IsDel=0
  if @tmpInt is null
     select @pwCount=0
  else
     select @pwCount=@tmpInt
  if @pwCount<>0
     select @pclewDesc='未受理短信：<span class="spLRed">'+cast(@pwCount as varchar(5))+'</span> 件'
  else
     select @pclewDesc='未受理短信：0 件'
  INSERT into @tmpTab(wCount,menuNo,clewDesc) VALUES(@pwCount,@pmenuNo,@pclewDesc)
End

--市级&区县ZF
IF CHARINDEX(@fpRole, '210,240,260,290,310,340')>0
Begin
  select @pmenuNo='3140'
  select @tmpInt=count(PkId) from [tWfSendBack] where SBDeptID=@deptId and SendState in (10,11) and dbo.frTelWFStep(WfId)>399 and IsDel=0
  if @tmpInt is null
     select @pwCount=0
  else
     select @pwCount=@tmpInt
  if @pwCount<>0
     select @pclewDesc='未签收电话工单：<span class="spLRed">'+cast(@pwCount as varchar(5))+'</span> 件'
  else
     select @pclewDesc='未签收电话工单：0 件'
  INSERT into @tmpTab(wCount,menuNo,clewDesc) VALUES(@pwCount,@pmenuNo,@pclewDesc)

  select @pmenuNo='3156'
  select @tmpInt=count(PkId) from [tWfSendBack] where SBDeptID=@deptId and SendState in(21,23) and BackState in (0,12,22) and IsDel=0
  if @tmpInt is null
     select @pwCount=0
  else
     select @pwCount=@tmpInt
  if @pwCount<>0
     select @pclewDesc='未答复电话工单：<span class="spLRed">'+cast(@pwCount as varchar(5))+'</span> 件'
  else
     select @pclewDesc='未答复电话工单：0 件'
  INSERT into @tmpTab(wCount,menuNo,clewDesc) VALUES(@pwCount,@pmenuNo,@pclewDesc)

  --新增 上级不同意退回电话工单
  select @pmenuNo='3157'
  select @tmpInt=count(PkId) from [tWfSendBack] where SBDeptID=@deptId and SendState=51 and dbo.frTelWFStep(WfId)>399 and IsDel=0
  if @tmpInt is null
     select @pwCount=0
  else
     select @pwCount=@tmpInt
  if @pwCount<>0
     select @pclewDesc='上级不同意退回电话工单：<span class="spLRed">'+cast(@pwCount as varchar(5))+'</span> 件'
  else
     select @pclewDesc='上级不同意退回电话工单：0 件'
  INSERT into @tmpTab(wCount,menuNo,clewDesc) VALUES(@pwCount,@pmenuNo,@pclewDesc)

  select @pmenuNo='3340'
  select @tmpInt=count(PkId) from [mWfSendBack] where SBDeptID=@deptId and SendState in (10,11) and dbo.frMailWFStep(WfId)>399 and IsDel=0
  if @tmpInt is null
     select @pwCount=0
  else
     select @pwCount=@tmpInt
  if @pwCount<>0
     select @pclewDesc='未签收信件工单：<span class="spLRed">'+cast(@pwCount as varchar(5))+'</span> 件'
  else
     select @pclewDesc='未签收信件工单：0 件'
  INSERT into @tmpTab(wCount,menuNo,clewDesc) VALUES(@pwCount,@pmenuNo,@pclewDesc)

  select @pmenuNo='3356'
  select @tmpInt=count(PkId) from [mWfSendBack] where SBDeptID=@deptId and SendState in(21,23) and BackState in (0,12,22) and IsDel=0
  if @tmpInt is null
     select @pwCount=0
  else
     select @pwCount=@tmpInt
  if @pwCount<>0
     select @pclewDesc='未答复信件工单：<span class="spLRed">'+cast(@pwCount as varchar(5))+'</span> 件'
  else
     select @pclewDesc='未答复信件工单：0 件'
 INSERT into @tmpTab(wCount,menuNo,clewDesc) VALUES(@pwCount,@pmenuNo,@pclewDesc)

 --新增 上级不同意退回信件工单
 select @pmenuNo='3357'
  select @tmpInt=count(PkId) from [mWfSendBack] where SBDeptID=@deptId and SendState in(51) and dbo.frMailWFStep(WfId)>399 and IsDel=0
  if @tmpInt is null
     select @pwCount=0
  else
     select @pwCount=@tmpInt
  if @pwCount<>0
     select @pclewDesc='上级不同意退回信件工单：<span class="spLRed">'+cast(@pwCount as varchar(5))+'</span> 件'
  else
     select @pclewDesc='上级不同意退回信件工单：0 件'
 INSERT into @tmpTab(wCount,menuNo,clewDesc) VALUES(@pwCount,@pmenuNo,@pclewDesc)

--   select @pmenuNo='3640'
--   select @tmpInt=count(PkId) from [pWfSendBack] where SBDeptID=@deptId and SendState in (10,11) and dbo.frMsgWFStep(WfId)>399 and IsDel=0
--   if @tmpInt is null
--      select @pwCount=0
--   else
--      select @pwCount=@tmpInt
--   if @pwCount<>0
--      select @pclewDesc='未签收短信工单：<span class="spLRed">'+cast(@pwCount as varchar(5))+'</span> 件'
--   else
--      select @pclewDesc='未签收短信工单：0 件'
--   INSERT into @tmpTab(wCount,menuNo,clewDesc) VALUES(@pwCount,@pmenuNo,@pclewDesc)
--
--   select @pmenuNo='3656'
--   select @tmpInt=count(PkId) from [pWfSendBack] where SBDeptID=@deptId and SendState in(21,23) and BackState in (0,12,22) and IsDel=0
--   if @tmpInt is null
--      select @pwCount=0
--   else
--      select @pwCount=@tmpInt
--   if @pwCount<>0
--      select @pclewDesc='未答复短信工单：<span class="spLRed">'+cast(@pwCount as varchar(5))+'</span> 件'
--   else
--      select @pclewDesc='未答复短信工单：0 件'
--   INSERT into @tmpTab(wCount,menuNo,clewDesc) VALUES(@pwCount,@pmenuNo,@pclewDesc)
End

--区县部门
IF CHARINDEX(@fpRole, '360,390')>0
Begin
  select @pmenuNo='3163'
  select @tmpInt=count(PkId) from [tWfSendBack] where SBDeptID=@deptId and SendState in (10,11) and dbo.frTelWFStep(WfId)>399 and IsDel=0
  if @tmpInt is null
     select @pwCount=0
  else
     select @pwCount=@tmpInt
  if @pwCount<>0
     select @pclewDesc='未签收电话工单：<span class="spLRed">'+cast(@pwCount as varchar(5))+'</span> 件'
  else
     select @pclewDesc='未签收电话工单：0 件'
  INSERT into @tmpTab(wCount,menuNo,clewDesc) VALUES(@pwCount,@pmenuNo,@pclewDesc)

  select @pmenuNo='3169'
  select @tmpInt=count(PkId) from [tWfSendBack] where SBDeptID=@deptId and SendState in(21,23) and BackState in (0,12,22) and IsDel=0
  if @tmpInt is null
     select @pwCount=0
  else
     select @pwCount=@tmpInt
  if @pwCount<>0
     select @pclewDesc='未答复电话工单：<span class="spLRed">'+cast(@pwCount as varchar(5))+'</span> 件'
  else
     select @pclewDesc='未答复电话工单：0 件'
  INSERT into @tmpTab(wCount,menuNo,clewDesc) VALUES(@pwCount,@pmenuNo,@pclewDesc)

  --新增 上级不同意退回电话工单
  select @pmenuNo='3157'
  select @tmpInt=count(PkId) from [tWfSendBack] where SBDeptID=@deptId and SendState=51 and dbo.frTelWFStep(WfId)>399 and IsDel=0
  if @tmpInt is null
     select @pwCount=0
  else
     select @pwCount=@tmpInt
  if @pwCount<>0
     select @pclewDesc='上级不同意退回电话工单：<span class="spLRed">'+cast(@pwCount as varchar(5))+'</span> 件'
  else
     select @pclewDesc='上级不同意退回电话工单：0 件'
  INSERT into @tmpTab(wCount,menuNo,clewDesc) VALUES(@pwCount,@pmenuNo,@pclewDesc)

  select @pmenuNo='3363'
  select @tmpInt=count(PkId) from [mWfSendBack] where SBDeptID=@deptId and SendState in (10,11) and dbo.frMailWFStep(WfId)>399 and IsDel=0
  if @tmpInt is null
     select @pwCount=0
  else
     select @pwCount=@tmpInt
  if @pwCount<>0
     select @pclewDesc='未签收信件工单：<span class="spLRed">'+cast(@pwCount as varchar(5))+'</span> 件'
  else
     select @pclewDesc='未签收信件工单：0 件'
  INSERT into @tmpTab(wCount,menuNo,clewDesc) VALUES(@pwCount,@pmenuNo,@pclewDesc)

  select @pmenuNo='3369'
  select @tmpInt=count(PkId) from [mWfSendBack] where SBDeptID=@deptId and SendState in(21,23) and BackState in (0,12,22) and IsDel=0
  if @tmpInt is null
     select @pwCount=0
  else
     select @pwCount=@tmpInt
  if @pwCount<>0
     select @pclewDesc='未答复信件工单：<span class="spLRed">'+cast(@pwCount as varchar(5))+'</span> 件'
  else
     select @pclewDesc='未答复信件工单：0 件'
  INSERT into @tmpTab(wCount,menuNo,clewDesc) VALUES(@pwCount,@pmenuNo,@pclewDesc)

  --新增 上级不同意退回信件工单
 select @pmenuNo='3357'
  select @tmpInt=count(PkId) from [mWfSendBack] where SBDeptID=@deptId and SendState in(51) and dbo.frMailWFStep(WfId)>399 and IsDel=0
  if @tmpInt is null
     select @pwCount=0
  else
     select @pwCount=@tmpInt
  if @pwCount<>0
     select @pclewDesc='上级不同意退回信件工单：<span class="spLRed">'+cast(@pwCount as varchar(5))+'</span> 件'
  else
     select @pclewDesc='上级不同意退回信件工单：0 件'
 INSERT into @tmpTab(wCount,menuNo,clewDesc) VALUES(@pwCount,@pmenuNo,@pclewDesc)

--   select @pmenuNo='3663'
--   select @tmpInt=count(PkId) from [pWfSendBack] where SBDeptID=@deptId and SendState in (10,11) and dbo.frMsgWFStep(WfId)>399 and IsDel=0
--   if @tmpInt is null
--      select @pwCount=0
--   else
--      select @pwCount=@tmpInt
--   if @pwCount<>0
--      select @pclewDesc='未签收短信工单：<span class="spLRed">'+cast(@pwCount as varchar(5))+'</span> 件'
--   else
--      select @pclewDesc='未签收短信工单：0 件'
--   INSERT into @tmpTab(wCount,menuNo,clewDesc) VALUES(@pwCount,@pmenuNo,@pclewDesc)
--
--   select @pmenuNo='3669'
--   select @tmpInt=count(PkId) from [pWfSendBack] where SBDeptID=@deptId and SendState in(21,23) and BackState in (0,12,22) and IsDel=0
--   if @tmpInt is null
--      select @pwCount=0
--   else
--      select @pwCount=@tmpInt
--   if @pwCount<>0
--      select @pclewDesc='未答复短信工单：<span class="spLRed">'+cast(@pwCount as varchar(5))+'</span> 件'
--   else
--      select @pclewDesc='未答复短信工单：0 件'
--   INSERT into @tmpTab(wCount,menuNo,clewDesc) VALUES(@pwCount,@pmenuNo,@pclewDesc)
End

--外包
IF CHARINDEX(@fpRole, '901,903,905,910,981')>0
Begin
  select @pmenuNo='2101'
  select @tmpInt=count(PkId) from [tTelGetDeal] where StateFlag=101 and IsDel=0 --??个人的
  if @tmpInt is null
     select @pwCount=0
  else
     select @pwCount=@tmpInt
  if @pwCount<>0
     select @pclewDesc='来电记录草稿：<span class="spLRed">'+cast(@pwCount as varchar(5))+'</span> 件'
  else
     select @pclewDesc='来电记录草稿：0 件'
  INSERT into @tmpTab(wCount,menuNo,clewDesc) VALUES(@pwCount,@pmenuNo,@pclewDesc)

  select @pmenuNo='2123'
  select @tmpInt=count(PkId) from [tTelGetDeal] where StateFlag=120 and IsDel=0 --??all
  if @tmpInt is null
     select @pwCount=0
  else
     select @pwCount=@tmpInt
  if @pwCount<>0
     select @pclewDesc='值班长退回：<span class="spLRed">'+cast(@pwCount as varchar(5))+'</span> 件'
  else
     select @pclewDesc='值班长退回：0 件'
  INSERT into @tmpTab(wCount,menuNo,clewDesc) VALUES(@pwCount,@pmenuNo,@pclewDesc)

  select @pmenuNo='2141'
  select @tmpInt=count(PkId) from [tTelGetDeal] where StateFlag in (120,122) and IsDel=0 --??all
  if @tmpInt is null
     select @pwCount=0
  else
     select @pwCount=@tmpInt
  if @pwCount<>0
     select @pclewDesc='待处理来电：<span class="spLRed">'+cast(@pwCount as varchar(5))+'</span> 件'
  else
     select @pclewDesc='待处理来电：0 件'
  INSERT into @tmpTab(wCount,menuNo,clewDesc) VALUES(@pwCount,@pmenuNo,@pclewDesc)

  select @pmenuNo='4731'
  select @tmpInt=count(PkId) from [tWorkFormBase] where CrtStepID=900 and IsDel=0
  if @tmpInt is null
     select @pwCount=0
  else
     select @pwCount=@tmpInt
  if @pwCount<>0
     select @pclewDesc='未回访电话工单：<span class="spLRed">'+cast(@pwCount as varchar(5))+'</span> 件'
  else
     select @pclewDesc='未回访电话工单：0 件'
  INSERT into @tmpTab(wCount,menuNo,clewDesc) VALUES(@pwCount,@pmenuNo,@pclewDesc)

End

--后台-tel
IF CHARINDEX(@fpRole, '920,980,981')>0
Begin
  select @pmenuNo='2141'
  select @tmpInt=count(PkId) from [tTelGetDeal] where StateFlag in(120,122) and IsDel=0
  if @tmpInt is null
     select @pwCount=0
  else
     select @pwCount=@tmpInt
  if @pwCount<>0
     select @pclewDesc='待处理来电记录：<span class="spLRed">'+cast(@pwCount as varchar(5))+'</span> 件'
  else
     select @pclewDesc='待处理来电记录：0 件'
  INSERT into @tmpTab(wCount,menuNo,clewDesc) VALUES(@pwCount,@pmenuNo,@pclewDesc)

  select @pmenuNo='3102'
  select @tmpInt=count(PkId) from [tWorkFormBase] where CrtStepID in(100,103) and IsDel=0
  if @tmpInt is null
     select @pwCount=0
  else
     select @pwCount=@tmpInt
  if @pwCount<>0
     select @pclewDesc='电话工单草稿：<span class="spLRed">'+cast(@pwCount as varchar(5))+'</span> 件'
  else
     select @pclewDesc='电话工单草稿：0 件'
  INSERT into @tmpTab(wCount,menuNo,clewDesc) VALUES(@pwCount,@pmenuNo,@pclewDesc)
  /*
  select @pmenuNo='3121'
  select @tmpInt=count(PkId) from [tWorkFormBase] where CrtStepID in(120) and IsDel=0
  if @tmpInt is null
     select @pwCount=0
  else
     select @pwCount=@tmpInt
  if @pwCount<>0
     select @pclewDesc='再次整理电话工单：<span class="spLRed">'+cast(@pwCount as varchar(5))+'</span> 件'
  else
     select @pclewDesc='再次整理电话工单：0 件'
  INSERT into @tmpTab(wCount,menuNo,clewDesc) VALUES(@pwCount,@pmenuNo,@pclewDesc)
  */
  select @pmenuNo='3123'
  select @tmpInt=count(PkId) from [tWorkFormBase] where CrtStepID in(201,251,401) and IsDel=0
  if @tmpInt is null
     select @pwCount=0
  else
     select @pwCount=@tmpInt
  if @pwCount<>0
     select @pclewDesc='被部门退回电话工单：<span class="spLRed">'+cast(@pwCount as varchar(5))+'</span> 件'
  else
     select @pclewDesc='被部门退回电话工单：0 件'
  INSERT into @tmpTab(wCount,menuNo,clewDesc) VALUES(@pwCount,@pmenuNo,@pclewDesc)

  select @pmenuNo='3136'
  select @tmpInt=count(PkId) from [tWorkFormBase] where CrtStepID in (810,820) and IsDel=0
  if @tmpInt is null
     select @pwCount=0
  else
     select @pwCount=@tmpInt
  if @pwCount<>0
     select @pclewDesc='待审定电话工单（部门已回）：<span class="spLRed">'+cast(@pwCount as varchar(5))+'</span> 件'
  else
     select @pclewDesc='待审定电话工单（部门已回）：0 件'
  INSERT into @tmpTab(wCount,menuNo,clewDesc) VALUES(@pwCount,@pmenuNo,@pclewDesc)
  /*
  select @pmenuNo='4731'
  select @tmpInt=count(PkId) from [tWorkFormBase] where CrtStepID=900 and IsDel=0
  if @tmpInt is null
     select @pwCount=0
  else
     select @pwCount=@tmpInt
  if @pwCount<>0
     select @pclewDesc='未回访电话工单：<span class="spLRed">'+cast(@pwCount as varchar(5))+'</span> 件'
  else
     select @pclewDesc='未回访电话工单：0 件'
  INSERT into @tmpTab(wCount,menuNo,clewDesc) VALUES(@pwCount,@pmenuNo,@pclewDesc)
  */
  select @pmenuNo='2311'
  select @tmpInt=count(PkId) from [mMailGetDeal] where StateFlag=141 and IsDel=0
  if @tmpInt is null
     select @pwCount=0
  else
     select @pwCount=@tmpInt
  if @pwCount<>0
     select @pclewDesc='待受理来信：<span class="spLRed">'+cast(@pwCount as varchar(5))+'</span> 件'
  else
     select @pclewDesc='待受理来信：0 件'
  INSERT into @tmpTab(wCount,menuNo,clewDesc) VALUES(@pwCount,@pmenuNo,@pclewDesc)

  select @pmenuNo='3303'
  select @tmpInt=count(PkId) from [mMailWorkForm] where CrtStepID in (201,251,401) and IsDel=0
  if @tmpInt is null
     select @pwCount=0
  else
     select @pwCount=@tmpInt
  if @pwCount<>0
     select @pclewDesc='被部门退回信件工单：<span class="spLRed">'+cast(@pwCount as varchar(5))+'</span> 件'
  else
     select @pclewDesc='被部门退回信件工单：0 件'
  INSERT into @tmpTab(wCount,menuNo,clewDesc) VALUES(@pwCount,@pmenuNo,@pclewDesc)

  select @pmenuNo='3316'
  select @tmpInt=count(PkId) from [mMailWorkForm] where CrtStepID in (810,820) and IsDel=0
  if @tmpInt is null
     select @pwCount=0
  else
     select @pwCount=@tmpInt
  if @pwCount<>0
     select @pclewDesc='待审定信件工单（部门已回）：<span class="spLRed">'+cast(@pwCount as varchar(5))+'</span> 件'
  else
     select @pclewDesc='待审定信件工单（部门已回）：0 件'
  INSERT into @tmpTab(wCount,menuNo,clewDesc) VALUES(@pwCount,@pmenuNo,@pclewDesc)

  select @pmenuNo='2601'
  select @tmpInt=count(PkId) from [pMsgGetDeal] where StateFlag in (171,181) and IsDel=0
  if @tmpInt is null
     select @pwCount=0
  else
     select @pwCount=@tmpInt
  if @pwCount<>0
     select @pclewDesc='未受理短信：<span class="spLRed">'+cast(@pwCount as varchar(5))+'</span> 件'
  else
     select @pclewDesc='未受理短信：0 件'
  INSERT into @tmpTab(wCount,menuNo,clewDesc) VALUES(@pwCount,@pmenuNo,@pclewDesc)

  select @pmenuNo='3603'
  select @tmpInt=count(PkId) from [pMsgWorkForm] where CrtStepID in (201,251,401) and IsDel=0
  if @tmpInt is null
     select @pwCount=0
  else
     select @pwCount=@tmpInt
  if @pwCount<>0
     select @pclewDesc='被部门退回短信工单：<span class="spLRed">'+cast(@pwCount as varchar(5))+'</span> 件'
  else
     select @pclewDesc='被部门退回短信工单：0 件'
  INSERT into @tmpTab(wCount,menuNo,clewDesc) VALUES(@pwCount,@pmenuNo,@pclewDesc)

  select @pmenuNo='3616'
  select @tmpInt=count(PkId) from [pMsgWorkForm] where CrtStepID in (810,820) and IsDel=0
  if @tmpInt is null
     select @pwCount=0
  else
     select @pwCount=@tmpInt
  if @pwCount<>0
     select @pclewDesc='待审定短信工单（部门已回）：<span class="spLRed">'+cast(@pwCount as varchar(5))+'</span> 件'
  else
     select @pclewDesc='待审定短信工单（部门已回）：0 件'
  INSERT into @tmpTab(wCount,menuNo,clewDesc) VALUES(@pwCount,@pmenuNo,@pclewDesc)
End

--后台-Mail-Msg
IF CHARINDEX(@fpRole, '930,940,980,983')>0
Begin
  select @pmenuNo='2311'
  select @tmpInt=count(PkId) from [mMailGetDeal] where StateFlag=141 and IsDel=0
  if @tmpInt is null
     select @pwCount=0
  else
     select @pwCount=@tmpInt
  if @pwCount<>0
     select @pclewDesc='待受理来信：<span class="spLRed">'+cast(@pwCount as varchar(5))+'</span> 件'
  else
     select @pclewDesc='待受理来信：0 件'
  INSERT into @tmpTab(wCount,menuNo,clewDesc) VALUES(@pwCount,@pmenuNo,@pclewDesc)

  select @pmenuNo='3303'
  select @tmpInt=count(PkId) from [mMailWorkForm] where CrtStepID in (201,251,401) and IsDel=0
  if @tmpInt is null
     select @pwCount=0
  else
     select @pwCount=@tmpInt
  if @pwCount<>0
     select @pclewDesc='被退回信件工单：<span class="spLRed">'+cast(@pwCount as varchar(5))+'</span> 件'
  else
     select @pclewDesc='被退回信件工单：0 件'
  INSERT into @tmpTab(wCount,menuNo,clewDesc) VALUES(@pwCount,@pmenuNo,@pclewDesc)

  select @pmenuNo='3312'
  select @tmpInt=count(PkId) from [mMailWorkForm] where CrtStepID>799 and CrtStepID<900 and IsDel=0
  if @tmpInt is null
     select @pwCount=0
  else
     select @pwCount=@tmpInt
  if @pwCount<>0
     select @pclewDesc='部门已回复信件工单：<span class="spLRed">'+cast(@pwCount as varchar(5))+'</span> 件'
  else
     select @pclewDesc='部门已回复信件工单：0 件'
  INSERT into @tmpTab(wCount,menuNo,clewDesc) VALUES(@pwCount,@pmenuNo,@pclewDesc)

  select @pmenuNo='4711'
  select @tmpInt=count(PkId) from [mMailWorkForm] where CrtStepID=900 and IsDel=0
  if @tmpInt is null
     select @pwCount=0
  else
     select @pwCount=@tmpInt
  if @pwCount<>0
     select @pclewDesc='未回访信件工单：<span class="spLRed">'+cast(@pwCount as varchar(5))+'</span> 件'
  else
     select @pclewDesc='未回访信件工单：0 件'
  INSERT into @tmpTab(wCount,menuNo,clewDesc) VALUES(@pwCount,@pmenuNo,@pclewDesc)

  select @pmenuNo='2601'
  select @tmpInt=count(PkId) from [pMsgGetDeal] where StateFlag in (171,181) and IsDel=0
  if @tmpInt is null
     select @pwCount=0
  else
     select @pwCount=@tmpInt
  if @pwCount<>0
     select @pclewDesc='未受理短信：<span class="spLRed">'+cast(@pwCount as varchar(5))+'</span> 件'
  else
     select @pclewDesc='未受理短信：0 件'
  INSERT into @tmpTab(wCount,menuNo,clewDesc) VALUES(@pwCount,@pmenuNo,@pclewDesc)

  select @pmenuNo='3603'
  select @tmpInt=count(PkId) from [pMsgWorkForm] where CrtStepID in (201,251,401) and IsDel=0
  if @tmpInt is null
     select @pwCount=0
  else
     select @pwCount=@tmpInt
  if @pwCount<>0
     select @pclewDesc='被退回短信工单：<span class="spLRed">'+cast(@pwCount as varchar(5))+'</span> 件'
  else
     select @pclewDesc='被退回短信工单：0 件'
  INSERT into @tmpTab(wCount,menuNo,clewDesc) VALUES(@pwCount,@pmenuNo,@pclewDesc)

  select @pmenuNo='3611'
  select @tmpInt=count(PkId) from [pMsgWorkForm] where CrtStepID>799 and CrtStepID<900 and IsDel=0
  if @tmpInt is null
     select @pwCount=0
  else
     select @pwCount=@tmpInt
  if @pwCount<>0
     select @pclewDesc='部门已回复短信工单：<span class="spLRed">'+cast(@pwCount as varchar(5))+'</span> 件'
  else
     select @pclewDesc='部门已回复短信工单：0 件'
  INSERT into @tmpTab(wCount,menuNo,clewDesc) VALUES(@pwCount,@pmenuNo,@pclewDesc)

  select @pmenuNo='4721'
  select @tmpInt=count(PkId) from [pMsgWorkForm] where CrtStepID=900 and IsDel=0
  if @tmpInt is null
     select @pwCount=0
  else
     select @pwCount=@tmpInt
  if @pwCount<>0
     select @pclewDesc='未回访短信工单：<span class="spLRed">'+cast(@pwCount as varchar(5))+'</span> 件'
  else
     select @pclewDesc='未回访短信工单：0 件'
  INSERT into @tmpTab(wCount,menuNo,clewDesc) VALUES(@pwCount,@pmenuNo,@pclewDesc)

End


SELECT tRow,wCount,menuNo,clewDesc FROM @tmpTab

set nocount off--打开计数
END

---

--select CHARINDEX('310', '310,362')